package liu.de.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.retry.annotation.EnableRetry;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * @author liude
 */
@Configuration
@EnableAsync
@EnableRetry
public class TaskConfig {
    @Bean
    public ThreadPoolTaskExecutor taskExecutor() {
        ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();

        taskExecutor.setCorePoolSize(2);

        //只有在queue满的情况下才会扩展pool
        taskExecutor.setMaxPoolSize(5);

        taskExecutor.setKeepAliveSeconds(10);
        taskExecutor.setQueueCapacity(2);

        taskExecutor.setAwaitTerminationSeconds(60);
        taskExecutor.setWaitForTasksToCompleteOnShutdown(true);

        return taskExecutor;
    }
}
